<?php 
/**
 * 
 */
function build_tree($rows,$root_id){
	// global	$rows;
	$children=findChild($rows,$root_id);
	if(empty($children)){
		return null;
	}
	foreach ($children as $k=>$v) {
		# code...
		$rescurTree=build_tree($rows,$v[id]);
		if(null!=$rescurTree){
			$children[$k]['children']=$rescurTree;
		}
	}
	return $children;
}

function findChild(&$arr,$id){
	$children=array();
	foreach($arr as $k=>$v){
		if($v['pid']==$id){
			$children[]=$v;
		}
	}
	return $children;
}



function show($trees){
    foreach($trees as $tree){
        if($tree['pid']>0){
            $pre='|'.str_repeat('-', substr_count($tree['path'], '-'));
        }
        $str.=$pre.$tree['title'].'<br/>';
        if(isset($tree['children'])){
            $str.=show($tree['children']);
        }
    }
    return $str;
}


function array_diff_assoc2_deep($array1, $array2) { 
    $ret = array(); 
    foreach ($array1 as $k => $v) {     
        if (!isset($array2[$k])) $ret[$k] = $v; 
        else if (is_array($v) && is_array($array2[$k])) $ret[$k] = array_diff_assoc2_deep($v, $array2[$k]); 
        else if ($v !=$array2[$k]) $ret[$k] = $v; 
        else 
        {
            unset($array1[$k]);
        }
    } 
    return $ret; 
} 


function upload(){    
	// 实例化上传类
    $upload = new \Think\Upload();    
    // 设置附件上传大小 
    $upload->maxSize=3145728; 
    // 设置附件上传类型  
    $upload->exts=array('jpg', 'gif', 'png', 'jpeg');
    // 上传文件     
    $info=$upload->upload(); 
    return $info;
}

/**
 * 将一张图片转成base64编码的文件
 *  @param string $image_file 文件的路径
 *  @return string 
 */
function getBase64Pic($image_file=''){
    if($image_file){
        $image_info = getimagesize($image_file);
        $base64_image_content = "data:{$image_info['mime']};base64," . chunk_split(base64_encode(file_get_contents($image_file)));
        return $base64_image_content;
    }
}

function getCurl($url){//get https的内容  
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_URL,$url);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);//不输出内容  
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);  
    $result =  curl_exec($ch);  
    curl_close ($ch);  
    return $result;  
}  

function dataPost($post_string, $url) {//POST方式提交数据  
    $context = array ('http' => array ('method' => "POST", 'header' => "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) \r\n Accept: */*", 'content' => $post_string ) );  
    $stream_context = stream_context_create ( $context );  
    $data = file_get_contents ( $url, FALSE, $stream_context );  
    return $data;  
}  